import React, { Component } from "react";

export default class TodoInput extends Component {
  state = {
    inputValue: "",
  };

  handleChange = (event) => {
    this.setState({
      inputValue: event.target.value,
    });
  };

  handleAdd = () => {
    console.log("输入内容:", this.state.inputValue);
  };

  render() {
    return (
      <div>
        {/* 受控组件 */}
        <input
          type="text"
          value={this.state.inputValue}
          onChange={this.handleChange}
          placeholder="请输入新待办事项"
        />{" "}
        <button onClick={this.handleAdd}>添加</button>
      </div>
    );
  }
}
